#include <bits/stdc++.h>
using namespace std;
#define ll  __int64
const ll mod = 1e9+7;
int main()
{
    ll a;
    ll e = 500000004;
    ll s = 333333336;
    while(scanf("%I64d",&a)!=EOF&&a)
    {
        ll ans = a*(a+1)%mod*e%mod*(2*a+1)%mod*s%mod;
        ans -= (4 + (a-1)*2)*(a-1)/4;
        if(a%2==0)  ans+=(a-1);
        while(ans<0)
            ans = (ans+mod)%mod;
        cout<<ans<<'\n';
    }
    return 0;
}
